Imports Microsoft.VisualBasic
Imports System
Imports System.Collections.Generic
Imports System.Text
Imports AllegNet
Imports Res = Ex04_LoadingImage

Namespace Ex04_LoadingImage
	Friend Class Main
		Inherits Api
		#Region "Properties"
		Private _Str_ScreenResolution As String = ""
		Private _Str_GfxMode As String = ""
		Private _Str_RenderingMode As String = ""
		Private _Str_BmpType As String = ""

		Public Property Str_ScreenResolution() As String
			Get
				Return _Str_ScreenResolution
			End Get
			Set
				_Str_ScreenResolution = Value
			End Set
		End Property
		Public Property Str_GfxMode() As String
			Get
				Return _Str_GfxMode
			End Get
			Set
				_Str_GfxMode = Value
			End Set
		End Property
		Public Property Str_RenderingMode() As String
			Get
				Return _Str_RenderingMode
			End Get
			Set
				_Str_RenderingMode = Value
			End Set
		End Property
		Public Property Str_BmpType() As String
			Get
				Return _Str_BmpType
			End Get
			Set
				_Str_BmpType = Value
			End Set
		End Property
		#End Region

		Friend Shared Fps As Integer = 0
		Friend Shared FpsToShow As Integer = 0

		Public Sub WinMain()
			Dim ScreenRes As ScreenResolution = ScreenResolution.Size_320_240
			Dim GfxMode As GfxModes = GfxModes.GfxAutoDetect
			Dim RenderingMode As RenderingModes = RenderingModes.Null
			Dim BmpTyp As BmpType = BmpType.Null


'			#Region "Get Params"
'			#Region "switch (Str_ScreenResolution)"
			Select Case Str_ScreenResolution
				Case "320 x 240"
					ScreenRes = ScreenResolution.Size_320_240
				Case "640 x 480"
					ScreenRes = ScreenResolution.Size_640_480
				Case "800 x 600"
					ScreenRes = ScreenResolution.Size_800_600
				Case "1024 x 768"
					ScreenRes = ScreenResolution.Size_1024_768
				Case "1088 x 612"
					ScreenRes = ScreenResolution.Size_1088_612
				Case "1152 x 864"
					ScreenRes = ScreenResolution.Size_1152_864
				Case "1280 x 720"
					ScreenRes = ScreenResolution.Size_1280_720
				Case "1280 x 768"
					ScreenRes = ScreenResolution.Size_1280_768
				Case "1280 x 800"
					ScreenRes = ScreenResolution.Size_1280_800
				Case "1280 x 960"
					ScreenRes = ScreenResolution.Size_1280_960
				Case "1280 x 1024"
					ScreenRes = ScreenResolution.Size_1280_1024
			End Select
'			#End Region

'			#Region " switch (Str_GfxMode)"
			Select Case Str_GfxMode
				Case "GfxAutoDetect"
					GfxMode = GfxModes.GfxAutoDetect
				Case "GfxAutoDetectFullScreen"
					GfxMode = GfxModes.GfxAutoDetectFullScreen
				Case "GfxAutoDetectWindowed"
					GfxMode = GfxModes.GfxAutoDetectWindowed
				Case "GfxDirectXAccel"
					GfxMode = GfxModes.GfxDirectXAccel
				Case "GfxDirectXWin"
					GfxMode = GfxModes.GfxDirectXWin
				Case "GfxDirectX"
					GfxMode = GfxModes.GfxDirectX
				Case "GfxDirectXSafe"
					GfxMode = GfxModes.GfxDirectXSafe
				Case "GfxDirectXSoft"
					GfxMode = GfxModes.GfxDirectXSoft
				Case "GfxDirectXOlv"
					GfxMode = GfxModes.GfxDirectXOlv
				Case "GfxGDI"
					GfxMode = GfxModes.GfxGDI
			End Select
'			#End Region

'			#Region "switch (Str_RenderingMode)"
			Select Case Str_RenderingMode
				Case "DoubleBuffering"
					RenderingMode = RenderingModes.DoubleBuffering
				Case "TripleBuffering"
					RenderingMode = RenderingModes.TripleBuffering
				Case "PageFlipping"
					RenderingMode = RenderingModes.PageFlipping

			End Select
'			#End Region

'			#Region "switch (Str_BmpType)"
			Select Case Str_BmpType
				Case "Memory"
					BmpTyp = BmpType.Memory
				Case "System"
					BmpTyp = BmpType.System
				Case "Video"
					BmpTyp = BmpType.Video

			End Select
'			#End Region
'			#End Region

			'Initialize AllegNet
			AllegNetInit()

			'Install Keyboard
			InstallKeyboard()

			'Install Timer
			InstallTimer()

			InstallMouse()

			'Set the application running on background
			SetDisplaySwitchMode(SwitchModes.SwitchBackground)

			'Set the render mode
			SetRenderMode(RenderingMode, BmpTyp)

			'Set the colorDepth
			SetColorDepth(CDepth.Depth_32_Bits) '32 Bits cause only this mode can accept ARGB

			'Set the Gfx Mode
			SetGfxMode(GfxMode, ScreenRes)


			Show8BitColor()
			ShowTrueColor()
			ShowTrueColorJpg()
			ShowTrueColorAlpha()


			'Exit AllegNet
			UninstallAllegNet()
		End Sub


		#Region "8 bit color"
		Public Sub Show8BitColor()
			Do While KbKey(AllKeys.Enter)

			Loop

			'Initialize main loop condition
			Dim Done As Boolean = False

			Do While Not Done
				'Acquire the Buffer
				AcquireBitmap(BufferedScreen)
				'Clear the buffer
				ClearBitmap(BufferedScreen)

				TextOutEx(BufferedScreen, DefaultFont, "Loadding 8 Bit color image", 10, 10, MakeCol(255, 255, 255), 0)
				TextOutEx(BufferedScreen, DefaultFont, "Press 'Enter' key to continue...", 10, 25, MakeCol(255, 255, 255), 0)

				'Release the Buffer
				ReleaseBitmap(BufferedScreen)

				'Render to screen with actual render settings
				ApiRenderer.Render()

				'Check for KeyPressed
				If KbKey(AllKeys.Enter) Then
					Done = True
				End If
			Loop
			Dim P As Palette = New Palette()
			Dim Color8Bit As Bmp = LoadBitmap("Color8Bit.bmp", P)

			Do While KbKey(AllKeys.Enter)

			Loop

			Done = False
			Do While Not Done
				'Acquire the Buffer
				AcquireBitmap(BufferedScreen)
				'Clear the buffer
				ClearBitmap(BufferedScreen)

				Blit(Color8Bit, BufferedScreen, 0, 0, 0, 0, Color8Bit.Width, Color8Bit.Height)

				'Release the Buffer
				ReleaseBitmap(BufferedScreen)

				'Render to screen with actual render settings
				ApiRenderer.Render()

				'Check for KeyPressed
				If KbKey(AllKeys.Enter) Then
					Done = True
				End If
			Loop
		End Sub
		#End Region

		#Region "True color Bmp"
		Public Sub ShowTrueColor()
			Do While KbKey(AllKeys.Enter)

			Loop

			'Initialize main loop condition
			Dim Done As Boolean = False

			Do While Not Done
				'Acquire the Buffer
				AcquireBitmap(BufferedScreen)
				'Clear the buffer
				ClearBitmap(BufferedScreen)

				TextOutEx(BufferedScreen, DefaultFont, "Loadding True color image", 10, 10, MakeCol(255, 255, 255), 0)
				TextOutEx(BufferedScreen, DefaultFont, "Press 'Enter' key to continue...", 10, 25, MakeCol(255, 255, 255), 0)

				'Release the Buffer
				ReleaseBitmap(BufferedScreen)

				'Render to screen with actual render settings
				ApiRenderer.Render()

				'Check for KeyPressed
				If KbKey(AllKeys.Enter) Then
					Done = True
				End If
			Loop

			Dim TrueColor As Bmp = LoadBitmap("TrueColor.bmp")

			Do While KbKey(AllKeys.Enter)

			Loop


			Done = False
			Do While Not Done
				'Acquire the Buffer
				AcquireBitmap(BufferedScreen)
				'Clear the buffer
				ClearBitmap(BufferedScreen)

				Blit(TrueColor, BufferedScreen, 0, 0, 0, 0, TrueColor.Width, TrueColor.Height)

				'Release the Buffer
				ReleaseBitmap(BufferedScreen)

				'Render to screen with actual render settings
				ApiRenderer.Render()

				'Check for KeyPressed
				If KbKey(AllKeys.Enter) Then
					Done = True
				End If
			Loop
		End Sub
		#End Region

		#Region "True color Jpg"
		Public Sub ShowTrueColorJpg()
			Do While KbKey(AllKeys.Enter)

			Loop

			'Initialize main loop condition
			Dim Done As Boolean = False

			Do While Not Done
				'Acquire the Buffer
				AcquireBitmap(BufferedScreen)
				'Clear the buffer
				ClearBitmap(BufferedScreen)

				TextOutEx(BufferedScreen, DefaultFont, "Loadding True color image Jpg", 10, 10, MakeCol(255, 255, 255), 0)
				TextOutEx(BufferedScreen, DefaultFont, "Press 'Enter' key to continue...", 10, 25, MakeCol(255, 255, 255), 0)

				'Release the Buffer
				ReleaseBitmap(BufferedScreen)

				'Render to screen with actual render settings
				ApiRenderer.Render()

				'Check for KeyPressed
				If KbKey(AllKeys.Enter) Then
					Done = True
				End If
			Loop

			Dim TrueColor As Bmp = LoadTrueColorPicture("TrueColor.Jpg")

			Do While KbKey(AllKeys.Enter)

			Loop


			Done = False
			Do While Not Done
				'Acquire the Buffer
				AcquireBitmap(BufferedScreen)
				'Clear the buffer
				ClearBitmap(BufferedScreen)

				Blit(TrueColor, BufferedScreen, 0, 0, 0, 0, TrueColor.Width, TrueColor.Height)

				'Release the Buffer
				ReleaseBitmap(BufferedScreen)

				'Render to screen with actual render settings
				ApiRenderer.Render()

				'Check for KeyPressed
				If KbKey(AllKeys.Enter) Then
					Done = True
				End If
			Loop
		End Sub
		#End Region

		#Region "True color with Alpha Transparency"
		Public Sub ShowTrueColorAlpha()
			Do While KbKey(AllKeys.Enter)

			Loop

			'Initialize main loop condition
			Dim Done As Boolean = False

			Do While Not Done
				'Acquire the Buffer
				AcquireBitmap(BufferedScreen)
				'Clear the buffer
				ClearBitmap(BufferedScreen)

				TextOutEx(BufferedScreen, DefaultFont, "Loadding True color image and apply alpha transparecy", 10, 10, MakeCol(255, 255, 255), 0)
				TextOutEx(BufferedScreen, DefaultFont, "Press 'Enter' key to continue...", 10, 25, MakeCol(255, 255, 255), 0)

				'Release the Buffer
				ReleaseBitmap(BufferedScreen)

				'Render to screen with actual render settings
				ApiRenderer.Render()

				'Check for KeyPressed
				If KbKey(AllKeys.Enter) Then
					Done = True
				End If
			Loop

			Dim Alpha01 As Bmp = LoadTrueColorPicture("Alpha01.png")
			Dim Alpha02 As Bmp = LoadTrueColorPicture("Alpha02.png")

			Do While KbKey(AllKeys.Enter)

			Loop

			'So we set the drawing mode to DrawModeTrans
			'there is no pattern here to apply so we pass null and 0 0 for the rest
			'This functino only affect drawing method like putpixel, but not Blit or draw sprite
			DrawingMode(DrawingModes.DrawModeTrans, Nothing, 0, 0)

			'Now with this function enable, we can directly draw the alpha chanel with the put pixel function
			'Only value between 0-255 are valid.
			SetWriteAlphaBlender()



			Dim x As Integer = 0
			Do While x < Alpha02.Width
				Dim y As Integer = 0
				Do While y < Alpha02.Height
					Dim Alpha As Integer = 50

					PutPixel(Alpha02, x, y, Alpha)
					y += 1
				Loop
				x += 1
			Loop


			'Now we allow drawing Bmp with Alpha chanel
			'Using drawSprite
			SetAlphaBlender()

			Done = False
			Do While Not Done
				'Acquire the Buffer
				AcquireBitmap(BufferedScreen)
				'Clear the buffer
				ClearBitmap(BufferedScreen)

				'DrawTransSprite(BufferedScreen, MySha, 0,0);
                DrawTransSprite(BufferedScreen, Alpha01, Integer.Parse(((ScreenWidth - Alpha01.Width) / 2).ToString()), Integer.Parse(((ScreenHeight - Alpha01.Height) / 2).ToString()))
				'DrawTransSprite(BufferedScreen, MySha, 0,0);
                DrawTransSprite(BufferedScreen, Alpha02, Integer.Parse(((ScreenWidth - Alpha02.Width) / 2).ToString()), Integer.Parse(((ScreenHeight - Alpha02.Height) / 2).ToString()))


				'Release the Buffer
				ReleaseBitmap(BufferedScreen)

				'Render to screen with actual render settings
				ApiRenderer.Render()

				'Check for KeyPressed
				If KbKey(AllKeys.Enter) Then
					Done = True
				End If
			Loop
		End Sub
		#End Region
	End Class
End Namespace
